package main

import (
	"fmt"
	"github.com/robfig/cron"
	"month_zg5/book_srv/common/initialize"
	"month_zg5/book_srv/models"
	"month_zg5/book_srv/service/es"
	"month_zg5/book_srv/service/mysql"
)

func main() {
	models.InitMigrate()
	go func() {
		MysqlToEs()
	}()
	initialize.InitGrpc()
}
func MysqlToEs() {
	c := cron.New()
	spec := "0 0 0 * * * ?"
	err := c.AddFunc(spec, func() {
		//同步
		book, err := mysql.GetBookAll()
		if err != nil {
			panic(err)
		}
		for _, v := range book {
			err = es.CreateBookEs("shang", v)
			if err != nil {
				panic(err)
			}
		}
	})
	fmt.Println(err)
	c.Start()

	select {}
}
